package otherTest;

import org.junit.Test;

/**
 * @Description :
 * @author: cww
 * @DateTime: 2018-07-28 22:56
 */

public class test1 {
    @Test
    public void test(){
        System.out.println(add(2,3,4,5));
    }

    private int add(int x ,int ... args){
        int sum = x;
        for (int i=0;i<args.length;i++){
            sum=sum+args[i];
        }
        return sum;
    }

    @Test
    public void test1(){
        //享元模式
        //基本数据的拆箱与装箱，当数值在-128~127之间(一个字节内)，装箱发现缓存中有一样的对象，则使用同一个引用，
        // 当大于127后就没有了，视为不常用
        Integer s1 = 15;
        Integer s2 = 15;
        Integer s3 = 127;
        Integer s4 = 127;
        Integer s5 = 128;
        Integer s6 = 128;
        Integer s7 = Integer.valueOf(10);
        Integer s8 = Integer.valueOf(10);
        System.out.println(s1 == s2);
        System.out.println(s3 == s4);
        System.out.println(s5 == s6);
        System.out.println(s7 == s8);
    }

    @Test
    public void test2(){
        boolean a = true;
        boolean a1 = true;
        short a2 = 2;
        short a3 = 3;
        char b = 10001;
        char b2 = (char) -b;
        //^是位运算符,代表按位异或
        a =  a^a1;
        a2= (short) (a2^a3);
        System.out.println(a);
//        System.out.println(a2);
        int c = (int) b2;
        System.out.println(c);
        System.out.println(Character.toString(b2));
        System.out.println((int)(b));
        int r = 9;
        int r1 = ~r;
        System.out.println(r1);
    }
    @Test
    public void test3(){
        char c = '\u0001';
        char c1 = 6;
        //计算机中的减法是将减数转补码在进行与被减数相加比如char -1为什么是65535 ，可以看成0+(-1),-1的补码是65535 1111 1111 1111
        c1 = (char) (0-1);
        System.out.println(c1);
        char c2 = 2;
        char c3 = 1;
        char c4 = (char) (c2-c3);
        System.out.println(c4);
        byte b1 = 1;
        byte b2 = 2;
        byte b3 = (byte) (b2-b1);
        System.out.println(b3);
        System.out.println(~b2+2);
    }

    @Test
    public void test4(){
        int i = 0;
        Leaf leaf = new Leaf();
        System.out.println(leaf.i);
    }
}
